#include "stdafx.h"
#include "SkeletonAnimation.h"


SkeletonAnimation::SkeletonAnimation()
{
	m_enable = true;
}

SkeletonAnimation::~SkeletonAnimation()
{
}

SkeletonAnimation::SkeletonAnimation(Camera *camera, Model *model, Shader *shader) :SkeletonAnimation()
{
	Init(camera, model, shader);
}
void SkeletonAnimation::Init(Camera *camera, Model *model, Shader *shader)
{
	RenderObject::Init(camera, &model->m_vaoMesh, model->m_materials, shader);
	SetBoundBox(model->m_boundingBoxMin, model->m_boundingBoxMax);
	m_animate.SetAnimData(&model->m_animationData);
}


void SkeletonAnimation::Init(Camera *camera, Shader *shader, AnimationData *animData, int numModel, Model **models)
{
	RenderObject::Init(camera, numModel);
	m_animate.SetAnimData(animData);
	if (models)
	{
		for (int i = 0; i < numModel; ++i)
		{
			SetMesh(i, &models[i]->m_vaoMesh, models[i]->m_materials, shader);
		}
	}
}

void SkeletonAnimation::Update()
{
	m_animate.Update();
}

void SkeletonAnimation::Draw()
{
	glm::mat4 *mats;
	int nmat = m_animate.GetBoneTransformMatrixs(&mats);
	Shaders::GetInstance()->m_uBoneTransformMatrix.SetBufferData(0, sizeof(glm::mat4)*nmat, mats, true);
	RenderObject::Draw();
}